<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">

<body data-type="index">
<div class="am-g tpl-g">
    <!-- 头部 -->
    <jsp:include page="common/header.jsp"></jsp:include>
    <!-- 风格切换 -->

    <!-- 侧边导航栏 -->
    <jsp:include page="common/memu.jsp"></jsp:include>


    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">

        <div class="row-content am-cf">
            <div class="row  am-cf">

                <div class="row">

                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">绑定邮箱</div>
                                <div class="widget-function am-fr">
                                    <a href="javascript:;" class="am-icon-cog"></a>
                                </div>
                            </div>
                            <div class="widget-body am-fr">

                                <form class="am-form tpl-form-line-form">


                                    <div class="am-form-group">
                                        <label for="email" class="am-u-sm-3 am-form-label">邮箱 <span class="tpl-form-line-small-title"></span></label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="email" placeholder="请输入邮箱地址">
                                            <small></small>
                                        </div>
                                    </div>

                                    <div class="am-form-group" id="bindButton">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <button onclick="bindEmail();" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success ">绑定</button>
                                        </div>
                                    </div>

                                    <div class="am-form-group" id="unBindButton">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <button onclick="unBindEmail();" type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success ">解绑</button>
                                        </div>
                                    </div>

                                </form>
                            </div>
                        </div>
                    </div>
                </div>





            </div>




        </div>



    </div>
</div>
</div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="your-modal">
    <div class="am-modal-dialog">
        <div class="am-modal-hd">
            <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
        </div>
        <div class="am-modal-bd">
            操作成功
        </div>
    </div>
</div>

<script src="/js/atm.js"></script>

<script>

    $('#emailA').addClass("active")

    function bindEmail() {
        $.get("/email/bindEmail.do", {
            email : $('#email').val()
        }, function (xx) {
            if (xx.code != 1000) {
                alert(xx.message);
                return;
            }

            alert('绑定成功，请到'+ $('#email').val()+'邮箱激活');
        });
    }

    (function checkEmail() {
        $.get("/email/checkBindEmail.do", {
            email : $('#email').val()
        }, function (xx) {
            if (xx.code != 1000) {
                alert(xx.message);
                return;
            }

            var userDetail = xx.data;
            if (userDetail.status == 2) {
                $('#bindButton').hide();
                $('#unBindButton').show();
                $('#email').val(userDetail.email);
            } else {
                $('#bindButton').show();
                $('#unBindButton').hide();
            }
        });
    })();

    function unBindEmail() {
        $.get("/email/unBindEmail.do", {
        }, function (xx) {
            if (xx.code != 1000) {
                alert(xx.message);
                return;
            }

            alert('解绑成功');

            //刷新页面
            window.location.reload();
        });
    }

</script>

</body>

</html>